package org.example.util.RabbitMQ;

import org.example.bean.User;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class Consumer {

    @RabbitHandler
    @RabbitListener(queuesToDeclare = @Queue("rabbitmq_queue_object"))
    public void process(User user) {
        System.out.println("消费者消费消息111user=====name：" + user.getUsername()+",password:"+user.getUserpwd());

    }

    // 消息转换器
    //在消费者端配置 Jackson2JsonMessageConverter：确保生产者和消费者使用相同的消息转换逻辑（如都使用 JSON 格式）。
    @Bean
    public MessageConverter jsonMessageConverter() {
        return new Jackson2JsonMessageConverter();
    }

}